package com.tobby.demo.jms.consumer;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.naming.NamingException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.tibco.tibjms.TibjmsConnectionFactory;

public class JmsConsumer {

	public static void main(String[] args) throws NamingException, JMSException {
		JmsConsumer consumer = new JmsConsumer();
		// consumer.consumeMessage();
		consumer.consumeMessageBySpring();
	}

	@SuppressWarnings("unused")
	private void consumeMessage() throws NamingException, JMSException {
		// PCS EMS Server URL: tcp://etclnx31u.nam.nsroot.net:8222
		TibjmsConnectionFactory connectionFactory = new TibjmsConnectionFactory("tcp://figarodev01.nam.nsroot.net:2002");
		connectionFactory.setMetric(1);
		connectionFactory.setMulticastEnabled(false);
		// PCS EMS Server Username/Password: PCSUser/PCSUser
		Connection connection = connectionFactory.createConnection("nyremoterouter01", "skynetadmin");
		connection.start();
		Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		// PCS EMS Server Outbound Topic: EM.ETRD.ALL.TO.PCS2
		Destination destination = session.createTopic("citi.credit.ny.test");
		MessageConsumer consumer = session.createConsumer(destination);
		while (true) {
			Message textMessage = (Message) consumer.receive();
			System.out.println(textMessage);
		}
	}

	@SuppressWarnings("unused")
	private void consumeMessageBySpring() {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
	}

}
